package org.jctc.els.modules.biz.controller.proTemplate;


import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.jctc.els.modules.biz.entity.proTemplate.*;
import org.jctc.els.modules.biz.service.proTemplate.ProjectReviewTemplateDetailedService;
import org.jctc.els.modules.biz.service.proTemplate.ProjectReviewTemplateService;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.annotation.MultipartConfig;


/**
 * 评审模板表;(els_project_review_template)表控制层
 * @author : http://www.chiner.pro
 * @date : 2022-6-21
 */
@Api(tags = "评审模板表对象功能接口")
@RestController
@RequestMapping("/projectReviewTemplate")
@NonDS
@ApiIgnore
@AllArgsConstructor
@MultipartConfig
public class ProjectReviewTemplateController{

    private ProjectReviewTemplateService projectReviewTemplateService;

    private ProjectReviewTemplateDetailedService projectReviewTemplateDetailedService;


    @ApiOperation("通过项目类别查询单条数据")
    @GetMapping("/projectReviewCategory")
    public R queryByProjectReviewCategory(@RequestParam("projectReviewCategory") Integer projectReviewCategory){
        ProjectReviewTemplateVO reviewTemplateVO =   projectReviewTemplateService.selectByCategory(projectReviewCategory);
        return R.data(reviewTemplateVO);
    }

    @ApiOperation("通过项目类别查询单条数据")
    @GetMapping("/projectReviewId")
    public R queryByProjectReviewProjectReviewId(@RequestParam("projectReviewId") Long projectReviewId){
        ProjectReviewTemplateVO reviewTemplateVO =   projectReviewTemplateService.selectByProjectReviewId(projectReviewId);
        return R.data(reviewTemplateVO);
    }

    @ApiOperation("新增数据")
    @PostMapping("/detailed")
    public ResponseEntity<ProjectReviewTemplateDetailed> add(@RequestBody ProjectReviewTemplateDetailed ProjectReviewTemplateDetailed){
        return ResponseEntity.ok(projectReviewTemplateDetailedService.insert(ProjectReviewTemplateDetailed));
    }

    @ApiOperation("分页查询")
    @GetMapping("/detailed-list")
    public R queryTreeList(@RequestParam("projectReviewId") Long projectReviewId) {
        List<TemplateDetailedTree> list =  projectReviewTemplateDetailedService.selectList(projectReviewId);
        return R.data(list);
    }

    /**
     * 分页查询
     *
     */
    @ApiOperation("分页查询")
    @GetMapping
    public R<Page<ProjectReviewTemplate>> paginQuery(Integer pageNum,Integer pageSize,String name){
        Page<ProjectReviewTemplate> projectReviewTemplatePage =  projectReviewTemplateService.selectPageList(pageNum,pageSize,name);
        return R.data(projectReviewTemplatePage);
    }

    @GetMapping("/list")
    @ApiOperation("查询所有数据")
    public R<List<ProjectReviewTemplate>> selectList(){
        List<ProjectReviewTemplate> projectReviewTemplates = projectReviewTemplateService.selectList();
        return R.data(projectReviewTemplates);
    }

    @ApiOperation("根据id查询详情")
    @GetMapping("/detailed/id")
    public R<ProjectReviewTemplateDetailedVO> selectDetailedById(@RequestParam("id") Long id){
        ProjectReviewTemplateDetailedVO detailed =  projectReviewTemplateDetailedService.selectDetailedById(id);
        return R.data(detailed);
    }

    @ApiOperation("根据id编辑询详情")
    @PutMapping("/detailed")
    public R updateDetailedById(@RequestBody ProjectReviewTemplateDetailedVO detailed){
        Boolean update = projectReviewTemplateDetailedService.update(detailed);
        return R.data(update);
    }

    /**
     * 新增数据
     *
     * @param projectReviewTemplate 实例对象
     * @return 实例对象
     */
    @ApiOperation("新增数据")
    @PostMapping
    public ResponseEntity<ProjectReviewTemplate> add(@RequestBody ProjectReviewTemplate projectReviewTemplate){
        return ResponseEntity.ok(projectReviewTemplateService.insert(projectReviewTemplate));
    }

    /**
     * 更新数据
     *
     * @param projectReviewTemplate 实例对象
     * @return 实例对象
     */
    @ApiOperation("更新数据")
    @PutMapping
    public ResponseEntity<ProjectReviewTemplate> edit(ProjectReviewTemplate projectReviewTemplate){
        return ResponseEntity.ok(projectReviewTemplateService.update(projectReviewTemplate));
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @ApiOperation("通过主键删除数据")
    @DeleteMapping("/batch")
    public R<Boolean> deleteBatchIds(@RequestBody List<String> ids){
        return R.status(projectReviewTemplateDetailedService.deleteBatchIds(ids));
    }

    @ApiOperation("通过主键删除数据")
    @DeleteMapping("{id}")
    public R<Boolean> deleteById(@PathVariable("id") Long id) {
        return R.status(projectReviewTemplateService.deleteById(id));
    }
}